package com.lintesis.lintesismodel.users;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Vector;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;


import javax.persistence.OneToMany;

import com.lintesis.lintesismodel.common.hibernate.BussinessObject;
import com.lintesis.lintesismodel.common.hibernate.Report;

@Entity
public class Role extends BussinessObject {
	@javax.persistence.SequenceGenerator(name = "SEQ_ROLE", sequenceName = "SEQ_ROLE", allocationSize = 1)
	@Id
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_ROLE")
	private Integer idRol;
	@Column(unique = true, nullable = false)
	private String roleName;
	private String description;

//	@ManyToMany
//	private List<Station> stations;
	@ManyToMany
	private List<UsrRight> usrRights;
	
	@ManyToMany
	private List<Report> reports;

//	@ManyToMany
//	private List<TerminalRight> terminalRights;

//	@ManyToMany
//	private List<Company> companies;

	@Override
	public String getObjectDescription()
	{
		String ret = "idRol=" + idRol + ", roleName=" + roleName;
		return ret;
	}

	public String getDescription()
	{
		return description;
	}

	public void setDescription(String description)
	{
		this.description = description;
	}

	public List<UsrRight> getUsrRights()
	{
		return usrRights;
	}

	public void setUsrRights(List<UsrRight> right)
	{
		this.usrRights = right;
	}

	public void setUsrRights(HashSet<UsrRight> right)
	{
		this.usrRights = new ArrayList<UsrRight>(right);
	}

	public Vector<String> getStringUsrRight()
	{
		Vector<String> ret = new Vector<String>();
		for (UsrRight permission : usrRights)
		{
			ret.add(permission.getKey());
			ret.addAll(permission.getChildrenString());
		}

		return ret;
	}

	public Integer getIdRol()
	{
		return idRol;
	}

	public void setIdRol(Integer idRol)
	{
		this.idRol = idRol;
	}

	public String getRoleName()
	{
		return roleName;
	}

	public void setRoleName(String roleName)
	{
		this.roleName = roleName;
	}

//	public List<Station> getStations()
//	{
//		return stations;
//	}
//
//	public void setStations(List<Station> stations)
//	{
//		this.stations = stations;
//	}
//
//	public void setStations(HashSet<Station> stations)
//	{
//		this.stations = new ArrayList<Station>(stations);
//	}

	public List<Report> getReports()
	{
		return reports;
	}

	public void setReports(List<Report> reports)
	{
		this.reports = reports;
	}

	public void setReports(HashSet<Report> reports)
	{
		this.reports = new ArrayList<Report>(reports);
	}

	@Override
	public Integer getId()
	{
		return getIdRol();
	}

	@Override
	public void doAfterDelete()
	{
		// TODO Auto-generated method stub
	}

	@Override
	public void doAfterSave()
	{
		// TODO Auto-generated method stub
	}

	@Override
	public void doBeforeDelete()
	{
		// TODO Auto-generated method stub
	}

	@Override
	public void doBeforeSave()
	{
	}

//	public List<Company> getCompanies()
//	{
//		return companies;
//	}
//
//	public void setCompanies(List<Company> companies)
//	{
//		this.companies = companies;
//	}
//
//	public void setCompanies(HashSet<Company> companies)
//	{
//		this.companies = new ArrayList<Company>(companies);
//	}
//
//	public List<TerminalRight> getTerminalRights()
//	{
//		return terminalRights;
//	}

//	public void setTerminalRights(List<TerminalRight> terminalRights)
//	{
//		this.terminalRights = terminalRights;
//	}
//
//	public void setTerminalRights(HashSet<TerminalRight> terminalRights)
//	{
//		this.terminalRights = new ArrayList<TerminalRight>(terminalRights);
//	}
	
//	public TerminalRight[] getTerminalRightsNativeArray()
//	{
//		TerminalRight[] p = new TerminalRight[0];
//		if (terminalRights != null)
//			p = terminalRights.toArray(p);
//		return p;
//	}
//
//	public void setTerminalRightsNativeArray(TerminalRight[] jobs)
//	{
//		this.terminalRights = new ArrayList<TerminalRight>(Arrays.asList(jobs));
//	}

}
